/**
 * Hash Params - trieda na reprezentaciu a parsovanie parametrov za #
 * @author Tomas Srna
 * @package bakalarka
 */

function hashParams(hashString) {
	
	// Typy parametrov
	this.paramTypes = {"by":0,"order":1,"page":2, "filter": 3};

	// Nacitanie parametrov zo stringu
	this.load = function(hashString) {
		if(hashString == undefined)
			return;
		var param, value;
		var i, toVal = false;
		param = "";
		value = "";
		for(i = 0; i < hashString.length; ++i) {
			if(hashString.charAt(i) == '#')
				continue;
			if(hashString.charAt(i) == '=')
				toVal = !toVal;
			else if(hashString.charAt(i) == '&') {
				toVal = false;
				if(this.paramTypes.hasOwnProperty(param))
					eval("this."+param+"=\""+value+"\"");
				param = "";
				value = "";
			} else {
				if(!toVal)
					param += hashString.charAt(i);
				else
					value += hashString.charAt(i);
			}
		}
		if(param != "" && value != "") {
			if(this.paramTypes.hasOwnProperty(param))
				eval("this."+param+"=\""+value+"\"");
		}
	};
	
	// V konstruktore zavolame load
	this.load(hashString);
	
	// Synteza stringu z parametrov
	this.get = function() {
		var result = Array();
		for(var param in this.paramTypes) {
			var value = eval("this."+param);
			if(value != undefined)
				result.push(param + "=" + value);
		}
		return result.join("&");
	};
	
	// Kopirovanie
	this.copy = function(from) {
		for(var param in this.paramTypes) {
			eval("this."+param+"=from."+param);
		}
	};
	
}
